package com.xuecheng;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.security.core.context.SecurityContextHolder;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

@SpringBootTest
public class RedisDome {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Test
    public void stringTest(){
        //插入一条string类型的信息
        stringRedisTemplate.opsForValue().set("www","12",10, TimeUnit.SECONDS);
        //读取一条string类型的信息
        Object www = stringRedisTemplate.opsForValue().get("www");
        System.out.println(www);
    }

    @Test
    public void hashTest(){
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("w","1");
        hashMap.put("e","2");
        //插入一条string类型的信息
        stringRedisTemplate.opsForHash().putAll("www1",hashMap);
        //读取一条string类型的信息
        Map<Object, Object> www1 = stringRedisTemplate.opsForHash().entries("www1");
        System.out.println(www1);
    }

    @Test
    public void test(){
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        System.out.println(principal);
    }
}
